CongSoThuNganPanel = Ext.extend(AbstractPanel, {
	layout : {
        type : 'vbox',
        align : 'stretch'
    },
    
    height : 900,
    
    initComponent : function() {
		this.formLabel = new Ext.form.Label({
			cls : 'main-title',
			text : lang.text.congSo.title
		});
		
		this.formLabelContainer = new Ext.Container({
			cls : 'field-align-center',
			items : [this.formLabel]
		});
		
		this.chonThuNganCombo = new Ext.form.ComboBox({
			name : 'nvThuNgan',
			hiddenName : 'nvThuNgan-id',
            fieldLabel : lang.text.congSo.chonThuNgan,
            width : 250,
            selectOnFocus : true,
            forceSelection : true,
            mode : 'local',
            triggerAction : 'all',
            valueField : 'id',
            displayField : 'maNv',
            store : new Ext.data.JsonStore({
                fields : ['id', 'maNv']
            })
		});
		
		this.xuatFileBtn = new Ext.Button({
			width : 70,
			text : lang.text.congSo.xuatFile
		});
		
		this.quyetToanBtn = new Ext.Button({
			width : 80,
			text : lang.text.quyetToan
		});
		
		var buttonCtn =  new Ext.Container({
			layout : 'hbox',
			items : [this.xuatFileBtn, {xtype : 'spacer', width : 13}, this.quyetToanBtn]
		});
		
		this.detailContainer = new Ext.Container({
			width : 1000,
			layout : 'form',
			height : 400,
			items : [Utility.createLayoutForComponent(this.chonThuNganCombo, 120), {xtype : 'spacer', height : 15},
			         buttonCtn]
		});
		
		this.items = [this.formLabelContainer, {xtype : 'spacer', height : 15}, this.detailContainer];
		CongSoThuNganPanel.superclass.initComponent.call(this);
	},
	
	afterRender : function() {
		this.submitButtons = [this.xuatFileBtn, this.quyetToanBtn];
		this.on('afterrender', this.initData, this);
		this.xuatFileBtn.on('click', this.xuatFileCongSo, this);
		this.quyetToanBtn.on('click', this.quyetToan, this);
		CongSoThuNganPanel.superclass.afterRender.call(this);		
	},
	
	xuatFileCongSo : function() {
		this.disableButtons();
		Utility.processExportWaitingWithParams("thuNgan/export", this.getForm().getFieldValues());
    	this.enableButtons();
	},
	
	quyetToan : function() {
		Ext.Msg.buttonText.ok = lang.text.ok;
		Ext.Msg.buttonText.cancel = lang.text.cancel;
		Ext.Msg.show({
			title : lang.text.notice,
			msg : lang.msg.confirmQuyetToanThuNgan,
			icon: Ext.MessageBox.WARNING,
			buttons: Ext.Msg.OKCANCEL,
			scope : this,
			fn: function(buttonId, text, opts){
				if (buttonId == "ok") {
					var waitingBox = Ext.MessageBox.wait(lang.text.pleaseWait, lang.text.loading);
					Ext.Ajax.request({
						url : 'thuNgan/quyetToan',
				        params : {
				        	'thuNganId' : this.chonThuNganCombo.getValue()
				        },
				        method : 'GET',
				        scope : this,
				        success : function(response, opts){
				        	waitingBox.hide();
				            var result = Ext.decode(response.responseText);
				            this.notifyMessage(result.msg);
				        }, 
				        failure : Ext.emptyFn
					});
				}
			}
		});
	},
	
	initData : function() {
		Ext.Ajax.request({
            url : 'thuNgan/initData',
            method : 'GET',
            scope : this,
            success : function(response, opts){
                var result = Ext.decode(response.responseText); 
                this.chonThuNganCombo.store.loadData(result.thuNgan);
                this.chonThuNganCombo.setValue(result.thuNgan[0].id)
                this.chonThuNganCombo.focus(true);
            }, 
            failure : function() {
            }
    	});
	},
	
	defaultActionHandler : function(){
		this.xuatFileCongSo();
	}
});